package com.hyl.common;

import java.io.Serializable;

public class ResponseData<T> implements Serializable {
    private String code;
    private String message;
    private T result;

    public ResponseData(){

    }

    public ResponseData(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseData(String code, String message, T result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    //泛型方法：第一个T的作用域只限于当前方法
    public static <T> ResponseData<T> success() {
        ResponseData<T> resData  = new ResponseData<>();
        resData.setCode("200");
        resData.setMessage("success");
        return resData;
    }

    public static <T> ResponseData<T> success(T result){
        ResponseData<T> resData  = new ResponseData<>();
        resData.setCode("200");
        resData.setMessage("success");
        resData.setResult(result);
        return resData;
    }

    public static <T> ResponseData<T> fail(String message){
        ResponseData<T> resData  = new ResponseData<>();
        resData.setCode("500");  //后台服务器业务错误
        resData.setMessage(message);
        return resData;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }
}
